package cn.edu.scau.cmi.zenglinghong.client;

import cn.edu.scau.cmi.zenglinghong.abstractFactory.domainAbstractClass.Meat;
import cn.edu.scau.cmi.zenglinghong.abstractFactory.factory.AbstractFactory;
import cn.edu.scau.cmi.zenglinghong.abstractFactory.factory.AonongFactory;
import cn.edu.scau.cmi.zenglinghong.abstractFactory.factory.TianbangFactory;
import cn.edu.scau.cmi.zenglinghong.abstractFactory.factory.WensFactory;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application{

	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		init(primaryStage);
	}
	
	public static void init(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Label label1 = new Label("请输入需要的品牌(Wens,Tianbang,Aonong):");
		TextField textField1 = new TextField();
		Label label2 = new Label("请输入需要的肉类(pork,beef,chicken):");
		TextField textField2 = new TextField();
		Button button = new Button("确认");
		TextArea textArea = new TextArea();
		textArea.setEditable(false);
		
		VBox root = new VBox();
		root.setSpacing(20);
		Scene scene = new Scene(root,400,300);
		primaryStage.setScene(scene);
		
		root.getChildren().add(label1);
		root.getChildren().add(textField1);
		root.getChildren().add(label2);
		root.getChildren().add(textField2);
		root.getChildren().add(button);
		root.getChildren().add(textArea);
		
		button.setOnAction(sigHandle -> {
			AbstractFactory factory = null;
			Meat meat = null;
			switch(textField1.getText()) {
			case "Wens":
				factory = new WensFactory(); break;
			case "Tianbang":
				factory = new TianbangFactory(); break;
			case "Aonong":
				factory = new AonongFactory(); break;
			default :
				textArea.setText("There is no such brand.");
				return ;
			}
			switch (textField2.getText()) {
			case "beef":
				meat = factory.getBeef(); break;
			case "chicken":
				meat = factory.getChicken(); break;
			case "pork":
				meat = factory.getPork(); break;
			default:
				textArea.setText("There is no such meat.");
			}
			if(meat != null) {
				//meat.getMeat();
				textArea.setText("你好，这是"+textField1.getText()+"的"+textField2.getText());
			}
		});
		
		primaryStage.setTitle("抽象工厂模式");
		primaryStage.show();
	}

//	public static void main(String[] args) {
//		Scanner in = new Scanner(System.in);
//		System.out.println("请输入需要的品牌(Wens,Tianbang,Aonong):");
//		String brand = in.next();
//		AbstractFactory factory = null;
//		switch(brand) {
//		case "Wens":
//			factory = new WensFactory(); break;
//		case "Tianbang":
//			factory = new TianbangFactory(); break;
//		case "Aonong":
//			factory = new AonongFactory(); break;
//		default :
//			System.out.println("There is no such brand.");
//			in.close();
//			return ;
//		}
//		System.out.println("请输入需要的肉类(pork,beef,chicken):");
//		String meatType = in.next();
//		in.close();
//		Meat meat = null;
//		switch(meatType) {
//		case "pork":
//			meat = factory.getPork();
//		case "beef":
//			meat = factory.getBeef();
//		case "chicken":
//			meat = factory.getChicken();
//		default :
//			System.out.println("There is no such meat.");
//		}
//		if(meat != null) {
//			meat.getMeat();
//		}
//	}

}
